package cn.nubia.admin.application.bean;

import cn.nubia.admin.application.apk.entity.ApkInfo;
import cn.nubia.admin.common.mybatis.annotations.Column;
import cn.nubia.admin.common.mybatis.annotations.Id;
import cn.nubia.admin.common.mybatis.annotations.Table;
import cn.nubia.admin.common.mybatis.annotations.UnColumn;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * Created by justin on 15/6/30.
 CREATE TABLE `nb_soft_item` (
 `soft_item_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '软件版本id',
 `soft_id` int(11) DEFAULT NULL COMMENT '软件id',
 `item_name` varchar(100) DEFAULT NULL COMMENT '软件具体名称',
 `version_code` varchar(0) DEFAULT NULL COMMENT '版本号',
 `version_name` varchar(128) DEFAULT NULL COMMENT '版本名称',
 `is_last_version` tinyint(4) DEFAULT NULL COMMENT '是否最新版本（1-最新 0-不是最新）',
 `device_type_list` varchar(20) DEFAULT NULL COMMENT '支持的设备类型',
 `icon_url` varchar(200) DEFAULT NULL COMMENT '图标路径',
 `file_url` varchar(200) DEFAULT NULL COMMENT '文件路径',
 `file_size` int(11) DEFAULT NULL COMMENT '软件大小（字节）',
 `file_md5` varchar(32) DEFAULT NULL COMMENT '文件md5',
 `signature` varchar(50) DEFAULT NULL COMMENT '软件签名',
 `create_time` int(11) DEFAULT NULL COMMENT '创建时间戳',
 `update_description` varchar(1000) DEFAULT NULL COMMENT '版本更新介绍',
 `last_modify_time` int(11) DEFAULT NULL COMMENT '最后修改时间',
 `publish_time` int(11) DEFAULT NULL COMMENT '上架时间',
 `download_number` int(11) DEFAULT NULL COMMENT '该版本总下载量',
 `state` smallint(6) DEFAULT NULL COMMENT '软件状态（-1-删除  0-待审核 1-已保存 2-审核中 3-上架 4-审核未通过 5-已下架 6-隐藏）',
 `min_fireware_id` int(11) DEFAULT NULL COMMENT '最小平台固件',
 `max_fireware_id` int(11) DEFAULT NULL COMMENT '最大平台固件',
 `is_ad` smallint(6) DEFAULT NULL COMMENT '是否含广告（0-无广告 1-有广告 2-含恶意广告）',
 `is_safe` smallint(6) DEFAULT NULL COMMENT '安全级别（0-不安全 1-安全 2-病毒/木马软件）',
 `resolution` int(11) DEFAULT NULL COMMENT '分辨率尺寸值',
 `qr_code` varchar(200) DEFAULT NULL COMMENT '二维码图片路径',
 `pay_type` smallint(6) DEFAULT NULL COMMENT '付费方式（0-免费 1-付费 2-限时免费）',
 `pay_price` decimal(9,2) DEFAULT NULL COMMENT '付费价格',
 `first_publish` tinyint(4) DEFAULT NULL COMMENT '是否首发（0-否 1-是）',
 `soft_src` int(11) DEFAULT NULL COMMENT '软件来源',
 `soft_src_code` varchar(50) DEFAULT NULL COMMENT '从其他系统导入的原软件编号',
 `create_admin_id` int(11) DEFAULT NULL COMMENT '添加软件的管理员id',
 `create_admin_name` varchar(20) DEFAULT NULL COMMENT '添加软件的管理员名称',
 `check_admin_id` int(11) DEFAULT NULL COMMENT '审核软件的管理员id',
 `check_admin_name` varchar(20) DEFAULT NULL COMMENT '审核软件的管理员名称',
 `check_reason` varchar(200) DEFAULT NULL COMMENT '审核原因备注',
 `language` int(11) DEFAULT NULL COMMENT '语言id',
 `permission` varchar(500) DEFAULT NULL COMMENT '软件拥有的执行权限',
 `pre_publish_time` int(11) DEFAULT NULL COMMENT '预发布时间',
 `check_time` int(11) DEFAULT NULL COMMENT '审核时间',
 `ad_icon_url` varchar(200) DEFAULT NULL COMMENT '广告图标地址',
 PRIMARY KEY (`soft_item_id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='软件版本表';

 SET FOREIGN_KEY_CHECKS = 1;
 */
@Table(value = "nb_soft_item")
public class SoftItem implements Serializable{
    private static final long serialVersionUID = -8244661101951482489L;

    public static final Integer STATE_DELETE = -1;
    public static final Integer STATE_WAIT_CHECK = 0;
    public static final Integer STATE_SAVE = 1;
    public static final Integer STATE_CHECKED = 3;
    public static final Integer STATE_CHECK_NO = 4;
    public static final Integer STATE_DOWN = 5;
    public static final Integer STATE_HIDDEN = 6;

    public static final int LAST_VERSION = 1;
    public static final int NOT_LAST_VERSION =0;

    public static final String COLUMN_STATE = "state";
    public static final String COLUMN_ITEMNAME = "itemName";
    public static final String COLUMN_VERSIONNAME = "versionName";
    public static final String COLUMN_VERSIONCODE = "versionCode";
    public static final String COLUMN_PUBLISH = "publishTime";
    public static final String COLUMN_SOFTID = "softId";
    public static final String COLUMN_ISLASTVERSION = "isLastVersion";

    public static final Map<String,String> softItemStatus = new TreeMap<>();
    static{
        softItemStatus.put("待审核","0");
        softItemStatus.put("已保存","1");
        softItemStatus.put("上架","3");
        softItemStatus.put("审核未通过","4");
        softItemStatus.put("已下架","5");
        softItemStatus.put("隐藏","6");
        softItemStatus.put("删除","-1");
    }



    @Id(value = "soft_item_id")
    private Integer id;
    @Column(value = "soft_id")
    private Integer softId;
    @Column(value = "item_name")
    private String itemName;//软件具体名称
    @Column(value = "version_code")
    private Integer versionCode;//版本号
    @Column(value = "version_name")
    private String versionName;//版本名称
    @Column(value = "is_last_version")
    private Integer isLastVersion;//是否最新版本（1-最新 0-不是最新）
    @Column(value = "device_type_list")
    private String deviceTypeList;//支持的设备类型
    @Column(value = "icon_url")
    private String iconUrl;//图标路径
    @Column(value = "file_url")
    private String fileUrl;//文件路径
    @Column(value = "file_size")
    private Integer fileSize;//软件大小（字节）
    @Column(value = "file_md5")
    private String fileMD5;
    @Column(value = "signature")
    private String signature;//软件签名--IG
    @Column(value = "create_time")
    private Integer createTime;
    @Column(value = "update_description")
    private String updateDescription;//版本更新介绍
    @Column(value = "last_modify_time")
    private Integer lastModifyTime;
    @Column(value = "publish_time")
    private Integer publishTime;
    @Column(value = "download_number")
    private Integer vdownloadNumber;//该版本总下载量
    @Column(value = "state")
    private Integer state;//软件状态（-1-删除  0-待审核 1-已保存  3-上架 4-审核未通过 5-已下架 6-隐藏）
    @Column(value = "min_fireware_id")
    private Integer minFirewareId;//最小平台固件
    @Column(value = "max_fireware_id")
    private Integer maxFirewareId;//最大平台固件
    @Column(value = "is_ad")
    private Integer adState;//是否含广告（0-无广告 1-有广告 2-含恶意广告）
    @Column(value = "is_safe")
    private Integer safeState;//安全级别（0-不安全 1-安全 2-病毒/木马软件）
    @Column(value = "resolution")
    private Integer resolution;//分辨率尺寸值
    @Column(value = "qr_code")
    private String qrCode;//二维码图片路径
    @Column(value = "pay_type")
    private Integer payType;//付费方式（0-免费 1-付费 2-限时免费）
    @Column(value = "pay_price")
    private Float payPrice;//付费价格
    @Column(value = "first_publish")
    private Integer firstPublish;//是否首发（0-否 1-是）
    @Column(value = "soft_src")
    private Integer softSrc;//'软件来源',---nb-dict-field
    @Column(value = "soft_src_code")
    private String softSrcCode;//从其他系统导入的原软件编号',--ig
    @Column(value = "create_admin_id")
    private Integer createAdminId;//添加软件的管理员id
    @Column(value = "create_admin_name")
    private String createAdminName;//创建人的管理员名称
    @Column(value = "check_admin_id")
    private Integer checkAdminId;//审核软件的管理员id
    @Column(value = "check_admin_name")
    private String checkAdminName;//审核软件的管理员名称
    @Column(value = "check_reason")
    private String checkReason;//审核原因备注
    @Column(value = "language")
    private Integer language;// '语言id',---nb-dict-field
    @Column(value = "permission")
    private String permission;//软件拥有的执行权限
    @Column(value = "pre_publish_time")
    private Integer prePublishTime;// '预发布时间',--ig
    @Column(value = "check_time")
    private Integer checkTime;//审核时间
    @Column(value = "ad_icon_url")
    private String adIconUrl;//广告图标地址
    @UnColumn
    private List<Terminal> terminals;

    public SoftItem(){}


    public SoftItem(ApkInfo apkInfo){
        //TODO:bean转换

    }

    public void copyStakeProperties(SoftItem domainSoftItem) {
        this.createAdminId = domainSoftItem.getCreateAdminId();
        this.createAdminName = domainSoftItem.getCreateAdminName();
        this.createTime = domainSoftItem.getCreateTime();
    }

    public Integer getAdState() {
        return adState;
    }

    public void setAdState(Integer adState) {
        this.adState = adState;
    }

    public Integer getSafeState() {
        return safeState;
    }

    public void setSafeState(Integer safeState) {
        this.safeState = safeState;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getSoftId() {
        return softId;
    }

    public void setSoftId(Integer softId) {
        this.softId = softId;
    }

    public String getItemName() {
        return itemName;
    }

    public void setItemName(String itemName) {
        this.itemName = itemName;
    }

    public Integer getVersionCode() {
        return versionCode;
    }

    public void setVersionCode(Integer versionCode) {
        this.versionCode = versionCode;
    }

    public String getVersionName() {
        return versionName;
    }

    public void setVersionName(String versionName) {
        this.versionName = versionName;
    }

    public Integer getIsLastVersion() {
        return isLastVersion;
    }

    public void setIsLastVersion(Integer isLastVersion) {
        this.isLastVersion = isLastVersion;
    }

    public String getDeviceTypeList() {
        return deviceTypeList;
    }

    public void setDeviceTypeList(String deviceTypeList) {
        this.deviceTypeList = deviceTypeList;
    }

    public String getIconUrl() {
        return iconUrl;
    }

    public void setIconUrl(String iconUrl) {
        this.iconUrl = iconUrl;
    }

    public String getFileUrl() {
        return fileUrl;
    }

    public void setFileUrl(String fileUrl) {
        this.fileUrl = fileUrl;
    }

    public Integer getFileSize() {
        return fileSize;
    }

    public void setFileSize(Integer fileSize) {
        this.fileSize = fileSize;
    }

    public String getFileMD5() {
        return fileMD5;
    }

    public void setFileMD5(String fileMD5) {
        this.fileMD5 = fileMD5;
    }

    public String getSignature() {
        return signature;
    }

    public void setSignature(String signature) {
        this.signature = signature;
    }

    public Integer getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Integer createTime) {
        this.createTime = createTime;
    }

    public String getUpdateDescription() {
        return updateDescription;
    }

    public void setUpdateDescription(String updateDescription) {
        this.updateDescription = updateDescription;
    }

    public Integer getLastModifyTime() {
        return lastModifyTime;
    }

    public void setLastModifyTime(Integer lastModifyTime) {
        this.lastModifyTime = lastModifyTime;
    }

    public Integer getPublishTime() {
        return publishTime;
    }

    public void setPublishTime(Integer publishTime) {
        this.publishTime = publishTime;
    }

    public Integer getVdownloadNumber() {
        return vdownloadNumber;
    }

    public void setVdownloadNumber(Integer vdownloadNumber) {
        this.vdownloadNumber = vdownloadNumber;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Integer getMinFirewareId() {
        return minFirewareId;
    }

    public void setMinFirewareId(Integer minFirewareId) {
        this.minFirewareId = minFirewareId;
    }

    public Integer getMaxFirewareId() {
        return maxFirewareId;
    }

    public void setMaxFirewareId(Integer maxFirewareId) {
        this.maxFirewareId = maxFirewareId;
    }



    public Integer getResolution() {
        return resolution;
    }

    public void setResolution(Integer resolution) {
        this.resolution = resolution;
    }

    public String getQrCode() {
        return qrCode;
    }

    public void setQrCode(String qrCode) {
        this.qrCode = qrCode;
    }

    public Integer getPayType() {
        return payType;
    }

    public void setPayType(Integer payType) {
        this.payType = payType;
    }

    public Float getPayPrice() {
        return payPrice;
    }

    public void setPayPrice(Float payPrice) {
        this.payPrice = payPrice;
    }

    public Integer getFirstPublish() {
        return firstPublish;
    }

    public void setFirstPublish(Integer firstPublish) {
        this.firstPublish = firstPublish;
    }

    public Integer getSoftSrc() {
        return softSrc;
    }

    public void setSoftSrc(Integer softSrc) {
        this.softSrc = softSrc;
    }

    public String getSoftSrcCode() {
        return softSrcCode;
    }

    public void setSoftSrcCode(String softSrcCode) {
        this.softSrcCode = softSrcCode;
    }

    public Integer getCreateAdminId() {
        return createAdminId;
    }

    public void setCreateAdminId(Integer createAdminId) {
        this.createAdminId = createAdminId;
    }

    public String getCreateAdminName() {
        return createAdminName;
    }

    public void setCreateAdminName(String createAdminName) {
        this.createAdminName = createAdminName;
    }

    public Integer getCheckAdminId() {
        return checkAdminId;
    }

    public void setCheckAdminId(Integer checkAdminId) {
        this.checkAdminId = checkAdminId;
    }

    public String getCheckAdminName() {
        return checkAdminName;
    }

    public void setCheckAdminName(String checkAdminName) {
        this.checkAdminName = checkAdminName;
    }

    public String getCheckReason() {
        return checkReason;
    }

    public void setCheckReason(String checkReason) {
        this.checkReason = checkReason;
    }

    public Integer getLanguage() {
        return language;
    }

    public void setLanguage(Integer language) {
        this.language = language;
    }

    public String getPermission() {
        return permission;
    }

    public void setPermission(String permission) {
        this.permission = permission;
    }

    public Integer getPrePublishTime() {
        return prePublishTime;
    }

    public void setPrePublishTime(Integer prePublishTime) {
        this.prePublishTime = prePublishTime;
    }

    public Integer getCheckTime() {
        return checkTime;
    }

    public void setCheckTime(Integer checkTime) {
        this.checkTime = checkTime;
    }

    public String getAdIconUrl() {
        return adIconUrl;
    }

    public void setAdIconUrl(String adIconUrl) {
        this.adIconUrl = adIconUrl;
    }

    public List<Terminal> getTerminals() {
        return terminals;
    }

    public void setTerminals(List<Terminal> terminals) {
        this.terminals = terminals;
    }

    public void addTerminal(Terminal terminal){
        if(terminals==null){
            terminals = new ArrayList<Terminal>();
        }
        this.terminals.add(terminal);
    }


}
